package de.lot.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;

/**
 * The actual Student who is part of the learning outcome examination
 * 
 * @author Stefan Kohler <kohler.stefan@gmail.com>
 */
@Entity
@Table(name = "STUDENT")
@Name("student")
public class Student implements Serializable {

    private Long studentNumber;
    private String firstName;
    private String lastName;
    private ProgramOfStudy programOfStudy;
    private Set<StudentLearningOutcome> studentLearningOutcome = new HashSet<StudentLearningOutcome>(0);

    @Id
    public Long getStudentNumber() {
        return studentNumber;
    }

    public void setStudentNumber(Long studentNumber) {
        this.studentNumber = studentNumber;
    }

    @Length(max = 50)
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Length(max = 50)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PROGRAMMOFSTUDY_ID", nullable = false)
    @NotNull
    public ProgramOfStudy getProgramOfStudy() {
        return programOfStudy;
    }

    public void setProgramOfStudy(ProgramOfStudy programOfStudy) {
        this.programOfStudy = programOfStudy;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "student")
    public Set<StudentLearningOutcome> getStudentLearningOutcome() {
        return studentLearningOutcome;
    }

    public void setStudentLearningOutcome(Set<StudentLearningOutcome> studentLearningOutcome) {
        this.studentLearningOutcome = studentLearningOutcome;
    }

    @Transient
    public String getName() {
        return firstName + " " + lastName;
    }
}
